//
//  UIBarButtonItem + Extension.swift
//  WeiBo01
//
//  Created by 黄跃奇 on 16/9/21.
//  Copyright © 2016年 itheima. All rights reserved.
//

import UIKit

extension UIBarButtonItem {
    
    convenience init(title: String, imageNamed: String? = nil, target: Any?, action: Selector) {
        //使用self调用其他构造函数
        self.init()
        
        let button = UIButton()
        
        if imageNamed != nil {
            //设置图片
            button.setImage(UIImage(named: imageNamed!), for: .normal)
        }
        
        button.addTarget(target, action: action, for: .touchUpInside)
        
        button.setTitle(title, for: .normal)
        //设置文字颜色
        button.setTitleColor(UIColor.darkGray, for: .normal)
        button.setTitleColor(UIColor.orange, for: .highlighted)
        //设置文字大小
        button.titleLabel?.font = UIFont.systemFont(ofSize: 14)
        button.sizeToFit()
        customView = button
    }
    
    
}





